/*
 * �쐬��: 2008/07/31
 *
 * ���̐������ꂽ�R�����g�̑}����e���v���[�g��ύX���邽��
 * �E�B���h�E > �ݒ� > Java > �R�[�h���� > �R�[�h�ƃR�����g
 */
package sort.ui.components;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import sort.record.Records;

/**
 * @author masaru-gotou
 *
 */
@SuppressWarnings("serial")
public class SortRepeatControlWindow extends JFrame implements Observer {
	private SortAnimationPanel vpanel;
	private RepeatSelectorPanel spanel;
//	private ResultPanel rpanel;
	private JButton b_start;
	private JButton b_stop;
//	private JButton b_init;
//	private SortResult result;
	private JCheckBox showSort;
	
	public SortRepeatControlWindow(String title) {
		super(title);
		setSize(400,400);
		Container container = getContentPane();
		container.setLayout(new BorderLayout());
		
		this.spanel = new RepeatSelectorPanel();
		
		JPanel cpanel = new JPanel(new FlowLayout());
		showSort = new JCheckBox("show sorting",true);
		cpanel.add(showSort);
//		b_init = new JButton("Init");
//		cpanel.add(b_init);
		b_start = new JButton("Start");
		cpanel.add(b_start);
		b_stop = new JButton("Stop");
		cpanel.add(b_stop);
		
		this.vpanel = new SortAnimationPanel();
//		this.rpanel = new ResultPanel();
		
		container.add(BorderLayout.NORTH, spanel);
		container.add(BorderLayout.CENTER, cpanel);
		container.add(BorderLayout.SOUTH, vpanel);
//		container.add(BorderLayout.EAST, cpanel);
//		container.add(BorderLayout.CENTER, vpanel);
//		container.add(BorderLayout.SOUTH, rpanel);
	}
	
//	public void addInitActionListener(ActionListener l) {
//		b_init.addActionListener(l);
//	}
	public void addStartActionListener(ActionListener l) {
		b_start.addActionListener(l);
	}
	public void addStopActionListener(ActionListener l) {
		b_stop.addActionListener(l);
	}
	public void setEnabledStartButton(boolean b) {
		b_start.setEnabled(b);
	}
	public void setEnabledStopButton(boolean b) {
		b_stop.setEnabled(b);
	}
	
	public void setArgorythmNames(String[] names) {
		spanel.setAlgorithmNames(names);
	}

	@Override
	public void update(Observable o, Object arg) {
		vpanel.drawRecords((Records)arg);
	}

	public String getArgorythmName() {
		return spanel.getArgorythmName();
	}

	public int getRecordCount() {
		return spanel.getRecordCount();
	}

	public void drawRecords(Records records) {
		vpanel.drawRecords(records);
	}

	public int getExecCount() {
		return spanel.getExecCount();
	}
	public boolean enabledShowSort() {
		return showSort.isSelected();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				SortRepeatControlWindow main = new SortRepeatControlWindow("Sort Demo");
				main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				main.pack();
				main.setVisible(true);
			}
		});
	}

}
